<template>
  <div>
    <el-card shadow="never">
      <el-table :data="state.dataSoucre" :loading="state.loading">
        <el-table-column prop="placeName" label="场地名称" align="center" />
        <el-table-column prop="status" label="状态" align="center" />
        <el-table-column prop="cost" label="价值量化" align="center" />
        <el-table-column prop="appraiseTime" label="鉴定时间" align="center" />
        <el-table-column fixed="right" align="center" label="操作" width="180px">
          <template #default="scope">
            <el-button link type="primary" @click="openForm('update', scope.row.id)">
              查看
            </el-button>
            <el-button link type="primary" @click="openForm('update', scope.row.id)">
              重新评估
            </el-button>
            <!-- <el-button
              link
              type="danger"
              @click="handleDelete(scope.row.id)"
            >
              删除
            </el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <!--      <Pagination-->
      <!--        v-model:limit="state.params.pageSize"-->
      <!--        v-model:page="state.params.pageNo"-->
      <!--        :total="state.total"-->
      <!--        @pagination="getList"-->
      <!--      />-->
    </el-card>
  </div>
</template>

<script lang="ts" setup>
import { getListApi, deleteApi, type List } from '@/api/appraisal/record'

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

defineOptions({ name: 'AppraisalRecord' })

type StateType = {
  dataSoucre: List[]
  loading: boolean
  total: number
  params: PageParam
}

const state = reactive<StateType>({
  dataSoucre: [],
  loading: false,
  total: 0,
  params: {
    pageNo: 1,
    pageSize: 100
  }
})

const getList = async () => {
  const { list, total } = await getListApi({
    ...state.params
  })
  state.dataSoucre = list
  state.total = total
}
getList()

/** 添加/修改操作 */
const openForm = (type: string, id?: number) => {
  // formRef.value.open(type, id)
}

const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await deleteApi(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}
</script>
